<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>消息推送</title>
    <script src="http://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
    <link href="http://cdn.bootcss.com/weui/1.0.2/style/weui.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/Public/Home/SaleManager/stylesheets/index.css">
</head>
<body>
<div class="pushHistory class_push">
    <header class = "all_header">
        <a class = "h_back h_back_1" href="javascript:history.back(-1);"><img src="/Public/Home/SaleManager/images/back_icon.png" alt=""></a>
        <span class = "h_title">消息推送</span>
        <a class = "h_add" href="javascript:void(0)"></a>
    </header>
    <div class="page">
        <div class="page__bd" style="height: 100%;">
            <div class="weui-tab">
                <div class="weui-navbar">
                    <div class="weui-navbar__item weui-bar__item_on">
                        推送消息
                    </div>
                    <div class="weui-navbar__item">
                        推送历史
                    </div>
                </div>
                <div class="weui-tab__panel">
                    <div class="push_list" style = "display: block;">
                        <div class="weui-cells__title">请选择推送对象</div>
                        <div class="weui-cells">
                            <div class="weui-cell weui-cell_select">
                                <div class="weui-cell__bd">
                                    <select class="weui-select" name="select1">
                                        <option selected="" value="all">我的所有患者</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title">请选择推送分类</div>
                        <div class="weui-cells">
                            <div class="weui-cell weui-cell_select">
                                <div class="weui-cell__bd">
                                    <select class="weui-select" name="select2">
                                        <option selected="">普通消息</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title">推送标题</div>
                        <div class="weui-cells" style = "padding: 10px 15px;">
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="title" name="title" maxlength="20" type="text" placeholder="请输入标题(20字以内)">
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title">编辑推送内容</div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" style = "padding: 10px 15px;">
                                <div class="weui-cell__bd">
                                    <textarea class="weui-textarea" id="txt" name="txt" placeholder="请输入文本" rows="3"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="weui-btn-area">
                            <a class="weui-btn push_btn" id="add">发 送</a>
                        </div>
                    </div>
                    <div class="push_list">
                        <volist name="push" id="vo">
                        <div class="weui-panel weui-panel_access">
                            <div class="weui-panel__bd">
                                <div class="weui-media-box weui-media-box_text">
                                    <div class="weui-media-box__title">
                                        <div>
                                            <span class = "all_user">所属所有患者</span>
                                            <span class = "infos">普通消息</span>
                                        </div>
                                        <div class = "nav_btn delete"  data-id="{$vo.id}">删除</div>
                                    </div>
                                    <p class="weui-media-box__desc">{$vo.title}</p>
                                    <div class = "push_date_w">
                                        <span>{$vo.date}</span>
                                        <span class = "push_state">已完成</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                            </volist>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src = "/Public/Home/SaleManager/js/index.js"></script>
<script src = "/Public/Home/SaleManager/js/androidback.js"></script>
</body>
</html>
<script type="text/javascript" src="/Public/Patient/js/layer_mobile/layer.js"></script>
<script type="text/javascript">
    $(function(){

            $(".class_push").on("click",".weui-navbar__item",function () {
                $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
                $(".push_list").hide().eq($(this).index()).show();
            });
            $(".class_push").on("click",".delete",function () {
                var id=$(this).data('id');
                var _this=$(this)
                var remove_url="{:U('remove_push')}";
                $.get(remove_url, {id:id}, function(data){
                    if(data.code==0){
                        _this.parents(".weui-panel").remove();
                    }
                });

            })

        //保存事件
        var issend = false;
        $('#add').click(function(){
            if(issend) return false;
            issend = true;
            var title=$('#title').val();
            var txt=$('#txt').val();
            //验证名字
            if(!title){
                issend = false;
                layer_msg('标题不能为空');
                return false;
            }
            if(!txt){
                issend = false;
                layer_msg('内容不能为空');
                return false;
            }
            $.post(location.href,{title:title,txt:txt},function (data){
                issend = false;
                if(data.code==0){
                    layer_msg('发送成功',1,function(){
                        location.href="{:U('index')}";
                    });
                }else{
                    layer_msg(data.msg);
                }
            },'json');
        });


    });
    //统一的layer提示弹层
    function layer_msg(msg,time,func){
        if(typeof time == 'undefined') time=2;
        if(typeof func != 'function') func=function(){};
        layer.open({
            content: msg
            ,skin: 'msg'
            ,time: time
            ,end: func()
        });
    }

</script>
